/*
 * Copyright 2012 Marsrutai.lt
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package lt.marsrutai.mobile.android.adapter;

import lt.marsrutai.mobile.android.R;
import lt.marsrutai.mobile.android.model.ArrivalTime;
import lt.marsrutai.mobile.android.util.HourMinuteFormat;
import lt.marsrutai.mobile.android.widget.ListViewAdapter;
import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;


public class RunStopAdapter extends ListViewAdapter<ArrivalTime> {
    
    String runId;
    String stopId;

    public RunStopAdapter(Activity activity, String runId, String stopId) {
        super(activity, R.layout.run_stops_item);
        this.runId = runId;
        this.stopId = stopId;
    }

    @Override
    public View doGetView(int position, View view, ViewGroup parent) {

        final ArrivalTime o = getItem(position);

        if (o != null) {
            TextView stopName = (TextView) view.findViewById(R.id.stop_name);
            TextView scheduledTime = (TextView) view.findViewById(R.id.scheduled_time);
            
            if (stopName != null) {
                stopName.setText(o.getStopName());
            }  
            if (scheduledTime != null) {
                scheduledTime.setText(HourMinuteFormat.format(o.getScheduledTime()));
            }          
            if (o.getStopId().equals(this.stopId)) {
                view.setBackgroundResource(R.color.secondary_light);                
            }
            else {
                view.setBackgroundResource(0);
            }
        
        }
        return view;
    }
}
